
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_put/controller/my_put_controller.dart';

class MyPutPage extends StatelessWidget {
  //路由
  static const String route = '/MyPutPage';

  const MyPutPage({super.key});

  @override
  Widget build(BuildContext context) {
    
    final MyPutController countController = Get.put<MyPutController>(MyPutController());

    return Scaffold(
      appBar: AppBar(
        title: const Text("Getx_put"),
        actions: [IconButton(
          icon: const Icon(Icons.refresh),
          onPressed: () {
            countController.updateAll();
          },)]
      ),
      
      body: SingleChildScrollView(
          child: Column(
        children: [
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: 
            ListTile(
              title: const Text("update Count"),
              subtitle: Obx(() => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('count = ${countController.count.value}'),
                      Text('count = ${countController.count1.value}'),
                    ],
                  )),
              onTap: () {
                countController.updateCount();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update String "),
              subtitle: Obx(() => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${countController.audi.value}'),
                      Text('我要买${countController.audi.value}'),
                    ],
                  )),
              onTap: () {
                countController.updateAudi();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update list"),
              subtitle: Obx(() => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${countController.list.toString()}'),
                      Text('我要买${countController.list1.toString()}'),
                    ],
                  )),
              onTap: () {
                //list, 要修改list里面的元素, 才会去更新UI
                countController.updateList();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update map"),
              subtitle: Obx(() => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${countController.map.toString()}'),
                      Text('我要买${countController.map1.toString()}'),
                    ],
                  )),
              onTap: () {
                countController.updateMap();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateModels"),
              subtitle: Obx(() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                    const Text("data: countController.models",
                        style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                    Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: countController.models.map((element) {
                          return Text('我要买${element.name}');
                        }).toList()),
                    const Text("data: countController.models1",
                        style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                    Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: countController.models1.map((element) {
                          return Text('我要买${element.name}');
                        }).toList()),
                  ])),
              onTap: () {
                countController.updateModels();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateRxModels"),
              subtitle: Obx(() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                    const Text("data: countController.rxModels",
                        style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                    Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: countController.rxModels.map((element) {
                          return Text('我要买${element.name}');
                        }).toList()),
                    const Text("data: countController.rxModels1",
                        style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                    Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: countController.rxModels1.map((element) {
                          return Text('我要买${element.name}');
                        }).toList()),
                  ])),
              onTap: () {
                countController.updateRxModels();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateModel"),
              subtitle: Obx(() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                    Text("data model: ${countController.model.value.name}"),
                    Text("data model1: ${countController.model1.value.name}"),
                  ])),
              onTap: () {
                countController.updateModel();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateIsTrue"),
              subtitle: Obx(() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                    Text("data isTrue: ${countController.isTrue.value}"),
                    Text("data isTrue1: ${countController.isTrue1.value}"),
                  ])),
              onTap: () {
                countController.updateIsTrue();
              },
            ),
          ),
        ],
      )),
    );
  }
}
